package cn.edu.njtc.service.impl;

import cn.edu.njtc.entity.dto.PatientMapStatsDto;
import cn.edu.njtc.entity.dto.ProvinceDetailDto;
import cn.edu.njtc.mapper.UserDetailMapper;
import cn.edu.njtc.mapper.UserDetailMapper2;
import cn.edu.njtc.service.PatientMapService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PatientMapServiceImpl implements PatientMapService {
    private final UserDetailMapper2 userDetailMapper;


    @Override
    public PatientMapStatsDto getNationalMapData() {
        PatientMapStatsDto statsDto = new PatientMapStatsDto();

        // 1. 获取全部患者数
        statsDto.setTotalPatients(userDetailMapper.countAllPatients());

        // 2. 获取本周新增患者数
        statsDto.setWeeklyNewPatients(userDetailMapper.countWeeklyNewPatients());

        // 3. 获取各省份统计数据
        statsDto.setProvinceStats(userDetailMapper.countPatientsGroupByProvince());

        return statsDto;
    }

    @Override
    public ProvinceDetailDto getProvinceData(String provinceName) {
        ProvinceDetailDto detailDto = new ProvinceDetailDto();
        detailDto.setProvinceName(provinceName);

        // 1. 获取该省份患者总数
        detailDto.setTotalPatients(userDetailMapper.countPatientsInProvince(provinceName));

        // 2. 获取该省份本周新增患者数
        detailDto.setWeeklyNewPatients(userDetailMapper.countWeeklyNewPatientsInProvince(provinceName));

        // 3. 获取该省份患者列表(按注册时间倒序)
        detailDto.setPatients(userDetailMapper.selectPatientsInProvince(provinceName));

        return detailDto;
    }
}